//
//  ReactNativeChildViewController.m
//  ModifyMetroDemo
//
//  Created by Marcus on 2020/3/8.
//  Copyright © 2020 Facebook. All rights reserved.
//

#import "RNChildViewController.h"
#import <React/RCTBridge+Private.h>
#import <React/RCTRootView.h>
#import "RCTBridge.h"
#import "AppDelegate.h"

@interface RNChildViewController ()

@end

@implementation RNChildViewController

- (void)viewDidLoad {
  [super viewDidLoad];
  // Do any additional setup after loading the view.
  [self initReactNativeContext];
}

- (void) initReactNativeContext{
  AppDelegate *myDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
  
  NSString *diffBundleFile = @"bundle/diff.ios.simple";
  NSLog(@"subapp: 业务包加载开始 ");
  NSURL *businessDiffFile = [[NSBundle mainBundle] URLForResource: diffBundleFile
                                                    withExtension:@"bundle"];
  NSData * businessDiffData = [NSData dataWithContentsOfURL:businessDiffFile];
  
  [(RCTBridge *) myDelegate.bridge.batchedBridge executeSourceCode:businessDiffData sync:NO];
  
  NSLog(@"subapp: 业务包加载结束 ");
  
  RCTRootView *rootView = [[RCTRootView alloc] initWithBridge: myDelegate.bridge
                                                   moduleName:@"simple"
                                            initialProperties:nil];
  rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
  self.view = rootView;
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
